<?php
    //print_r($_FILES);
    $a = $_FILES['file']['error'];
    if($a==0){//上传成功
        $array = array('jpg','gif','png','jpeg');
        $b = explode('.',$_FILES['file']['name']);
        $c = end($b);//获取$b的后缀
        $d = array_search($c,$array);
        if($d===false){
            echo "<script>alert('文件格式错误，请重新上传！');history.go(-1);</script>";
        }else{//判断文件的大小
            define("size",1024*1024);
            $Size = $_FILES['file']['size'];
            if($Size>size){
                echo "<script>alert('文件过大，请重新上传！');history.go(-1);</script>";
            }else{
                echo "<script>alert('上传成功！')</script>";
                echo "<p>文件名：{$_FILES['file']['name']}</p>";
                echo "<p>文件类型：{$_FILES['file']['type']}</p>";
                echo "<p>文件大小：{$_FILES['file']['size']}kb</p>";
                echo "<p>文件临时存储位置：{$_FILES['file']['tmp_name']}</p>";
                if (file_exists('upload/'.$_FILES['file']['name'])){
                    echo "保存错误：{$_FILES['file']['name']}文件已存在！";
                }else{
                    move_uploaded_file($_FILES['file']['tmp_name'],'upload/'.$_FILES['file']['name']);
                    echo "文件已存储于：upload/{$_FILES['file']['name']}";
                }
            }
        }
    }
?>